﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace BaseSet.Entity.Common.Player
{
    /// <summary>
    /// 输出HTML脚本形式的播放器
    /// </summary>
    public class Player
    {
        /// <summary>
        /// 拼出flash的HTML代码
        /// </summary>
        /// <param name="FlashAddress">flash地址</param>
        /// <param name="strWidth">宽度</param>
        /// <param name="strHeight">高度</param>
        /// <returns>字符串</returns>
        public static string OutputFlashScript(string FlashAddress, string strWidth, string strHeight)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<object id=\\\"flvFlash\\\" classid=\\\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\\\" width=\\\"" + strWidth + "\\\" height=\\\"" + strHeight + "\\\">");
            sb.Append("	<param name=\\\"movie\\\" value=\\\"\"+" + FlashAddress + "+\"\\\" />");
            sb.Append("	<param name=\\\"allowscriptaccess\\\" value=\\\"always\\\" />");
            sb.Append("		<param name=\\\"allowFullScreen\\\" value=\\\"true\\\" />");
            sb.Append("		<param name=\\\"wmode\\\" value=\\\"transparent\\\" />");
            sb.Append("	<!--[if !IE]>-->");
            sb.Append("	<object id=\\\"flvFlash\\\" type=\\\"application/x-shockwave-flash\\\" data=\\\"\"+" + FlashAddress + "+\"\\\" width=\\\"" + strWidth + "\\\" height=\\\"" + strHeight + "\\\">");
            sb.Append("		<param name=\\\"allowscriptaccess\\\" value=\\\"always\\\" />");
            sb.Append("		<param name=\\\"allowFullScreen\\\" value=\\\"true\\\" />");
            sb.Append("		<param name=\\\"wmode\\\" value=\\\"transparent\\\" />");
            sb.Append("	<!--<![endif]-->");
            sb.Append("		<a href=\\\"http://www.adobe.com/go/getflashplayer\\\">");
            sb.Append("			<img src=\\\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\\\" alt=\\\"Get Adobe Flash player\\\" />");
            sb.Append("		</a>");
            sb.Append("	<!--[if !IE]>-->");
            sb.Append("	</object>");
            sb.Append("	<!--<![endif]-->");
            sb.Append("</object>");
            return sb.ToString();
        }

        /// <summary>
        /// 在网页上插入播放器
        /// </summary>
        /// <param name="MediaAddress">媒体文件地址</param>
        /// <param name="strWidth">宽度</param>
        /// <param name="strHeight">高度</param>
        /// <param name="AutoStart">autostart：true为音乐文件上传完后自动开始播放，默认为false（否）</param>
        /// <returns>返回字符串</returns>
        public static string OutputScriptWindowsMediaPlayer(string MediaAddress, string strWidth, string strHeight, bool AutoStart)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<object id=\\\"flvMedia\\\" width=\\\"{0}\\\" height=\\\"{1}\\\" ", strWidth, strHeight);
            if (HttpContext.Current.Request.Browser.Browser.Equals("IE"))
            {
                sb.Append("classid=\\\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\\\" type=\\\"application/x-oleobject\\\"");
            }
            else
            {
                sb.Append("type=\\\"application/x-ms-wmp\\\"");
            }
            sb.AppendFormat("><param name=\\\"url\\\" value=\\\"{0}\\\"><param name=\\\"autoStart\\\" value=\\\"{1}\\\"><param name=\\\"invokeURLs\\\" value=\\\"0\\\"><param name=\\\"uiMode\\\" value=\\\"None\\\"><param name=\\\"stretchToFit\\\" value=\\\"1\\\"></object>", MediaAddress, Convert.ToInt32(AutoStart));
            return sb.ToString();
        }

    }
}
